<template>
  <Find @findClicked="findData3" @Launchform="Launchform5" :OriginalFilter="{ static: true }" :formList="formList1" />
  <h1 style="font-size: 18px; text-align: center">订单分析(按交期)</h1>
  <Table
    :isLoading="isLoading"
    :tableHeader="tableHeader"
    :tableData="ReplenishmentInformationInquiryTableDate"
    @currentRow="currentRow2"
    :summaryData="summaryData"
    summary
  />

  <el-dialog v-model="dialogVisible20" :title="active" width="70%" class="dialog pb0">
    <Table
      :isLoading="isLoading"
      :tableHeader="tableHeader1"
      :tableData="queryMethods1TableDate"
      :TableHeight="90"
      @currentRow="currentRow3"
      :summaryData="summaryData1"
      summary
    />
  </el-dialog>

  <el-dialog v-model="dialogVisible21" :title="active1" width="70%" class="dialog pb0">
    <Table :isLoading="isLoading" :tableHeader="tableHeader3" :tableData="getNodeMethodsT" :TableHeight="90" @currentRow="currentRow3" />
  </el-dialog>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
  name: 'orderDeliveryDate'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import { ref, onMounted } from 'vue'
import { query, query1, getNode } from '@/api/Control/WEB/orderDeliveryDate'
const active1 = ref('')

// 计算金额总数
const summaryData1 = ref<any[]>([
  {
    index: 1,
    num: 0
  },
  {
    index: 2,
    num: 0
  },
  {
    index: 3,
    num: 0
  },
  {
    index: 4,
    num: 0
  },
  {
    index: 5,
    num: 0
  },
  {
    index: 6,
    num: 0
  },
  {
    index: 7,
    num: 0
  },
  {
    index: 8,
    num: 0
  },
  {
    index: 9,
    num: 0
  },
  {
    index: 10,
    num: 0
  }
])
// 工艺节点查询
const getNodeParms = ref<any>({
  date: '',
  type: ''
})

// 计算金额总数
const summaryData = ref<any[]>([
  {
    index: 1,
    num: 0
  },
  {
    index: 2,
    num: 0
  },
  {
    index: 3,
    num: 0
  },
  {
    index: 4,
    num: 0
  },
  {
    index: 5,
    num: 0
  },
  {
    index: 6,
    num: 0
  },
  {
    index: 7,
    num: 0
  },
  {
    index: 8,
    num: 0
  },
  {
    index: 9,
    num: 0
  },
  {
    index: 10,
    num: 0
  }
])

const dialogVisible21 = ref(false)

const imgList = ref<any>([])

const active = ref('')
const queryMethods1TableDate = ref([])

const getNodeMethodsT = ref([])

const getNodeMethods = async () => {
  const res = await getNode(getNodeParms.value)
  getNodeMethodsT.value = res
  imgList.value = res.map((item: any) => {
    return item.photoPath
  })
}

const currentRow3 = (row: any, item: any) => {
  if(getNodeParms.value.date === ''){
    const date = new Date(row.title);
const isValidDate = !isNaN(date.getTime());

getNodeParms.value.date = isValidDate ? row.title : '';
  }

  active1.value = row.title + '    ' + active.value + '月份主面料未完成订单明细'
  if (item === '主面料') {
    getNodeParms.value.type = 0
    dialogVisible21.value = true
    getNodeMethods()
  }
  if (item === '冲裁') {
    getNodeParms.value.type = 1
    dialogVisible21.value = true
    getNodeMethods()
  }
  if (item === '工艺') {
    getNodeParms.value.type = 2
    dialogVisible21.value = true
    getNodeMethods()
  }
  if (item === '配套') {
    getNodeParms.value.type = 3
    dialogVisible21.value = true
    getNodeMethods()
  }
  if (item === '针车') {
    getNodeParms.value.type = 4
    dialogVisible21.value = true
    getNodeMethods()
  }
  if (item === '大底') {
    getNodeParms.value.type = 5
    dialogVisible21.value = true
    getNodeMethods()
  }
  if (item === '成型') {
    getNodeParms.value.type = 6
    dialogVisible21.value = true
    getNodeMethods()
  }
}

const queryParms1 = ref('')

const queryMethods1 = async () => {
  const res = await query1(queryParms1.value)
  queryMethods1TableDate.value = res.map((item:any) => {
    item.backgroundColor = 'red'
    return item
  })
  summaryData1.value[0].num = res.reduce((total: any, currentItem: { orderQty: any }) => total + Number(currentItem.orderQty || 0), 0)
  summaryData1.value[1].num = res.reduce((total: any, currentItem: { finQty: any }) => total + Number(currentItem.finQty || 0), 0)
  summaryData1.value[2].num = res.reduce((total: any, currentItem: { unFinQty: any }) => total + Number(currentItem.unFinQty || 0), 0)
  summaryData1.value[3].num = res.reduce((total: any, currentItem: { mtlQty: any }) => total + Number(currentItem.mtlQty || 0), 0)
  summaryData1.value[4].num = res.reduce((total: any, currentItem: { cut1Qty: any }) => total + Number(currentItem.cut1Qty || 0), 0)
  summaryData1.value[5].num = res.reduce((total: any, currentItem: { cut2Qty: any }) => total + Number(currentItem.cut2Qty || 0), 0)
  summaryData1.value[6].num = res.reduce((total: any, currentItem: { cut3Qty: any }) => total + Number(currentItem.cut3Qty || 0), 0)
  summaryData1.value[7].num = res.reduce((total: any, currentItem: { cut4Qty: any }) => total + Number(currentItem.cut4Qty || 0), 0)
  summaryData1.value[8].num = res.reduce((total: any, currentItem: { cut5Qty: any }) => total + Number(currentItem.cut5Qty || 0), 0)
  summaryData1.value[9].num = res.reduce((total: any, currentItem: { cut6Qty: any }) => total + Number(currentItem.cut6Qty || 0), 0)
}


const ReplenishmentInformationInquiryTableDate = ref([])

const dialogVisible20 = ref(false)

const currentRow2 = (row: any, item: any) => {
  const date = new Date(row.title);
const isValidDate = !isNaN(date.getTime());

getNodeParms.value.date = isValidDate ? row.title : '';
  if (item === 'title') {
    active.value = row.title + '月份订单分析明细'
    dialogVisible20.value = true
    queryParms1.value = row.title
    queryMethods1()
  }
}

const isLoading = ref(false)

const queryParms = ref('')

const queryMethods = async () => {
  isLoading.value = true
  const res = await query(queryParms.value)
  ReplenishmentInformationInquiryTableDate.value = res.map((item:any) => {
    item.backgroundColor = 'red'
    return item
  })

  summaryData.value[0].num = res.reduce((total: any, currentItem: { orderQty: any }) => total + Number(currentItem.orderQty || 0), 0)
  summaryData.value[1].num = res.reduce((total: any, currentItem: { finQty: any }) => total + Number(currentItem.finQty || 0), 0)

  summaryData.value[2].num = res.reduce((total: any, currentItem: { unFinQty: any }) => total + Number(currentItem.unFinQty || 0), 0)
  summaryData.value[3].num = res.reduce((total: any, currentItem: { mtlQty: any }) => total + Number(currentItem.mtlQty || 0), 0)

  summaryData.value[4].num = res.reduce((total: any, currentItem: { cut1Qty: any }) => total + Number(currentItem.cut1Qty || 0), 0)

  summaryData.value[5].num = res.reduce((total: any, currentItem: { cut2Qty: any }) => total + Number(currentItem.cut2Qty || 0), 0)

  summaryData.value[6].num = res.reduce((total: any, currentItem: { cut3Qty: any }) => total + Number(currentItem.cut3Qty || 0), 0)

  summaryData.value[7].num = res.reduce((total: any, currentItem: { stitchQty: any }) => total + Number(currentItem.stitchQty || 0), 0)
  summaryData.value[8].num = res.reduce((total: any, currentItem: { soleQty: any }) => total + Number(currentItem.soleQty || 0), 0)

  summaryData.value[9].num = res.reduce((total: any, currentItem: { lastQty: any }) => total + Number(currentItem.lastQty || 0), 0)

  isLoading.value = false
}

onMounted(() => {
  // 获取当前日期
  const today = new Date()

  // 获取当前年份
  const currentYear = today.getFullYear() // 例如：2025

  // 设置默认值
  formList1.value[0].inputValue = currentYear
})

const formList1 = ref<any>([
  {
    type: 'input',
    inputPlaceholder: '请输入月份',
    inputValue: ''
  }
])

const tableHeader = ref([
  {
    label: '交期月份',
    prop: 'title',
    backgroundColor: true
  },
  {
    label: '接单数',
    prop: 'orderQty'
  },
  {
    label: '已完成',
    prop: 'finQty'
  },
  {
    label: '未完成',
    prop: 'unFinQty'
  },
  {
    Multistage: true,
    label: '各流程节点未完成',
    children: [
      {
        label: '主面料',
        prop: 'mtlQty'
      },
      {
        label: '冲裁',
        prop: 'cut1Qty'
      },
      {
        label: '工艺',
        prop: 'cut2Qty'
      },
      {
        label: '配套',
        prop: 'cut3Qty'
      },
      {
        label: '针车',
        prop: 'stitchQty'
      },
      {
        label: '大底',
        prop: 'soleQty'
      },
      {
        label: '成型',
        prop: 'lastQty'
      }
    ]
  }
])

const tableHeader1 = ref([
  {
    label: '品牌',
    prop: 'title',
    
  },
  {
    label: '接单数',
    prop: 'orderQty'
  },
  {
    label: '已完成',
    prop: 'finQty'
  },
  {
    label: '未完成',
    prop: 'unFinQty'
  },
  {
    Multistage: true,
    label: '各流程节点未完成',
    children: [
      {
        label: '主面料',
        prop: 'mtlQty',
        backgroundColor: true
      },
      {
        label: '冲裁',
        prop: 'cut1Qty',
        backgroundColor: true
      },
      {
        label: '工艺',
        prop: 'cut2Qty',
        backgroundColor: true
      },
      {
        label: '配套',
        prop: 'cut3Qty',
        backgroundColor: true
      },
      {
        label: '针车',
        prop: 'stitchQty',
        backgroundColor: true
      },
      {
        label: '大底',
        prop: 'soleQty',
        backgroundColor: true
      },
      {
        label: '成型',
        prop: 'lastQty',

        
      }
    ]
  }
])

const tableHeader3 = ref([
  {
    label: '指令号',
    prop: 'lotNo'
  },
  {
    label: '图片',
    fixed: true,
    prop: 'photoPath',
    type: 'img',
    srcList: imgList
  },
  {
    label: '品牌',
    prop: 'custom'
  },
  {
    label: '型体',
    prop: 'style'
  },
  {
    label: '颜色',
    prop: 'color'
  },
  {
    label: '订单数',
    prop: 'orderQty'
  },
  {
    label: '未完成',
    prop: 'unQty'
  }
])

const Launchform5 = (row: any) => {
  queryParms.value = row[0].inputValue
  queryMethods()
}

const findData3 = (row: string) => {
  if (row === '置空') {
  }
}
</script>

<style lang="less" scoped></style>
